#include<asm/io.h>   
#include"led_opr.h"


static volatile unsigned int *CCM_CCGR1;
static volatile unsigned int *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3;
static volatile unsigned int *GPIO5_GDIR;
static volatile unsigned int *GPIO5_DR;

static int led_init(int which)
{
    unsigned int val;
	
	 if(which == 0)
    {
	   /*地址映射*/
	    if (!CCM_CCGR1)
        {
            CCM_CCGR1 = ioremap(0x20C406C, 4);
            IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = ioremap(0x2290014, 4);
            GPIO5_GDIR = ioremap(0x020AC004, 4);
            GPIO5_DR = ioremap(0x020AC000, 4);
        }
		
   
		/* 使能GPIO5,bit30~bit31 */
		*CCM_CCGR1 |= (3<<30);
        
		/* 配置GPIO5_3为GPIO，MUX_MODE：101 */
		//*IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 &= ~0xf;   //清除
		//*IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 |= 0x5;    //这种需要赋值两遍

		val = *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3;
		val &= ~0xf;
		val |= 0x5;
        *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = val;

		
		/* 配置GPIO5_3为OUTPUT,1 */
		*GPIO5_GDIR |= (1<<3);
   }
  return 0;
}

static int  led_ioctl(int which    , int status)
{
     if(which == 0)
     {
	    /* 根据user_buf 设置引脚状态 */
	    if(status)
		{
		   *GPIO5_DR &= ~(1<<3);//低电平，打开LED
		}
		else
		{
		   *GPIO5_DR |= (1<<3);
		}
     }
    return 0;
}

static struct led_opr led_fops = {
    .num  = 1,
    .init = led_init,
    .ctl  = led_ioctl,
};

struct led_opr *get_led_fops(void)
{
    return &led_fops;
}



